export default class ZZAutoScroll {
	public bodyDoms: HTMLElement;
	public tsDoms: HTMLElement;
	public boxDoms: HTMLElement;
	constructor(bodyDom: HTMLElement, tsDom: HTMLElement, boxDom: HTMLElement) {
		this.bodyDoms = bodyDom;
		this.tsDoms = tsDom;
		this.boxDoms = boxDom;
	}
	public timer: NodeJS.Timer | undefined;
	public rollStop = () => {
		this.timer ? clearInterval(this.timer) : "";
	};
	public rollStart = (t: number) => {
		this.rollStop();
		this.timer = setInterval(() => {
			if (this.boxDoms.scrollTop >= this.bodyDoms.scrollHeight) {
				this.boxDoms.scrollTop = 0;
			} else {
				this.boxDoms.scrollTop++;
			}
			if (!this.bodyDoms.scrollHeight) {
				this.rollStop();
				return;
			}
		}, t);
	};
	public roll = (t: number) => {
		this.tsDoms.innerHTML = this.bodyDoms.innerHTML;
		this.boxDoms.scrollTop = 0;
		this.rollStart(t);
	};
}
